function distinctObj(arr, obj) {
	var result = [];
	if (arr.length > 0)
	{
		result.push(arr[0][obj]);
		for (var i = 0; i < arr.length; i++)
		{
			if (result.indexOf(arr[i][obj]) == -1)
				result.push(arr[i][obj]);
		}
	}
	return result;
}
function groupPortfolio(arr) {
	var result = [], arrChild = [], check = false;
	arrChild.push(arr[0]);
	arr.splice(0,1);
	result.push(arrChild);
	for (var i = 0; i < arr.length; i++)
	{
		check = false;
		for(var j = 0; j < result.length; j++)
		{
			if (result[j][0].PortCode == arr[i].PortCode)
			{
				result[j].push(arr[i]);
				arr.splice(i,1);
				i--;
				check = false;
				break;
			}
			check = true;
		}
		if (check)
		{
			arrChild = [];
			arrChild.push(arr[i]);
			result.push(arrChild);
			arr.splice(i,1);
			i--;
		}
	}
	return result;
}
function sumPrice(arr, cur, filter) {
	var result = [], sum = 0;
	for (var i = 0 ; i < cur.length; i++)
	{
		sum = 0;
		for (var j = 0; j < arr.length; j++)
		{
			if (filter == 1)
			{
				if (cur[i] == arr[j].PosCurrency)
				{	
					sum += parseInt(arr[j].PosMarketValue);
					arr.splice(j,1);
					j--;
				}
			}
			else if (filter == 2)
			{
				if (cur[i] == arr[j].PosCategory)
				{	
					sum += parseInt(arr[j].PosMarketValue);
					arr.splice(j,1);
					j--;
				}
			}
			else if (filter == 3)
			{
				if (cur[i] == arr[j].PosDepository)
				{	
					sum += parseInt(arr[j].PosMarketValue);
					arr.splice(j,1);
					j--;
				}
			}
		}
		result.push({ obj: cur[i], value: sum});
	}
	return result;
}
function IsJson(str) {
    try {
        JSON.parse(str);
    } catch (e) {
        return false;
    }
    return true;
}
function textWidth(text){
  var el = '#getTextWidth';
  var html_calc = '<span>' + text + '</span>';
  $(el).html(html_calc);
  $(el).css("display","block");
  var width = $(el).find('span:first').width();
  $(el).css("display","none");
  $(el).html('');
  return width;
};